package com.car.controller;

import com.alibaba.fastjson.JSON;
import com.car.entity.Cartable;
import com.car.entity.Storetable;
import com.car.entity.User;
import com.car.service.CardetailstableService;
import com.car.service.CartableService;
import com.car.service.StoretableService;
import com.car.service.UserService;
import com.car.vo.CartableVo;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/car")
public class CartableController<T> {
	@Autowired
	StoretableService storeService;
	@Autowired
	UserService userservice;
	@Autowired
	CartableService carService;
	@Autowired
	CardetailstableService carDetailService;
	
	@RequestMapping("/selBycarId")
	public CartableVo selBycarId(String carId){
		CartableVo carinfo=carService.selBycarId(carId);
		carinfo.setDayCount(0);
		return carinfo;
	}
	@RequestMapping("/selByBelong")
	public List<T> selByBelong(@RequestParam("belong") String belong){
		if(belong.equals("1")){
			
			return storeService.selectAll();
		}
		else{
			
			return userservice.selectAll();
		}
	}
	
	@RequestMapping("/addCar")
	public int addCar(CartableVo cartable){
		int i=carService.insert(cartable);
		int f=carDetailService.insert(cartable);
		if(i!=0&&f!=0){
			return f;
		}
		else{
			return 0;
		}
		
	}
	
}